package com.zx.oa.controller;

import com.zx.oa.entity.Student;
import com.zx.oa.service.student.StudentService;
import com.zx.oa.service.student.StudentServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/addStudent")
public class StudentServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //获取注册学生信息
        String major = request.getParameter("major");   //专业
        Integer classId = Integer.parseInt(request.getParameter("classID")); //班级
        String name = request.getParameter("name"); //名字
        String fromschool = request.getParameter("fromschool"); //院校
        String education = request.getParameter("education"); //学历
        String username = request.getParameter("username"); //登录账号
        String userpwd = request.getParameter("userpwd");  //密码

        Student student = new Student(name,classId,fromschool,education,username,userpwd);

        StudentService stuService  = new StudentServiceImpl();
        boolean b = stuService.addStudent(student);
        if (b){
            response.sendRedirect("chaservlet.do");
        }else{
            response.sendRedirect(request.getContextPath()+"/common/500.jsp");
        }

    }
}
